We are going to make some plotly plots.

Load packages and data

library(tidyverse)
library(p8105.datasets)
library(plotly)
library(dplyr)
library(readxl)
library(ggplot2)
library(patchwork)
library(lubridate)
library(ggridges)

let’s get some data.

data("ny_noaa")

noaa_tidy = ny_noaa |>  
  janitor::clean_names() |>  
  separate(date, into = c("year", "month", "day"), convert = TRUE) |> 
  mutate(
    prcp = prcp / 10 ,
    tmax = as.numeric(tmax) / 10,
    tmin = as.numeric(tmin) / 10,
    year = as.numeric(year),
    day = as.numeric(day), 
    month = recode_factor(month,
          "01" = "January",
          "02" = "February",
          "03" = "March",
          "04" = "April",
          "05" = "May",
          "06" = "June",
          "07" = "July",
          "08" = "August",
          "09" = "September",
          "10" = "October",
          "11" = "November",
          "12" = "December"
          )) |>  
  relocate(year, month, day, everything())

Scatterplot

tmax_noaa = noaa_tidy |>  
  group_by(id, year, month) |>  
  summarize(mean_tmax = mean(tmax, na.rm = TRUE))
## `summarise()` has grouped output by 'id', 'year'. You can override using the
## `.groups` argument.
tmax_noaa |> 
    plot_ly(
        x = ~year, y = ~mean_tmax, color = ~ month,
    type = "scatter", mode = "markers", alpha = .5, text = "Data from the NOAA dataset"
    )
## Warning: Ignoring 36342 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

Boxplots

tmax_noaa |>
    plot_ly(
        y = ~mean_tmax, color = ~month,
        type = "box", colors = "viridis")
## Warning: Ignoring 36342 observations

Bar plot

tmax_noaa |>
    plot_ly(
        x = ~month, y = ~mean_tmax,
        type = "bar", colors = "viridis")
## Warning: Ignoring 36342 observations

Create a dashboard…

Not here though.